package cmj.cloudmusic.adapter.gridview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cmj.cloudmusic.R;
import cmj.cloudmusic.entity.MusicList;

/**
 * Created by 王虎 on 2016/12/19.
 */

public class ZB_baseAdapter extends BaseAdapter {
    Context context;
    List<MusicList> list;

    public ZB_baseAdapter(Context context, List<MusicList> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;

        if (convertView==null){
            viewHolder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.zhuboredio_item,null);
            viewHolder.title= (TextView) convertView.findViewById(R.id.title);
            viewHolder.author= (TextView) convertView.findViewById(R.id.author);
            viewHolder.img= (ImageView) convertView.findViewById(R.id.img);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        MusicList musicList=list.get(position);
        viewHolder.img.setImageResource(musicList.getImageurl());
        viewHolder.title.setText(musicList.getTitle());
        viewHolder.author.setText(musicList.getAuthor());
        return convertView;
    }
    class ViewHolder{
        TextView title;
        TextView author;
        ImageView img;
    }

}
